<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Adding a New Agent - Reinforcement Learning Coach Documentation</title>
  

  <link rel="shortcut icon" href="../../img/favicon.ico">

  
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="../../css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../css/theme_extra.css" type="text/css" />
  <link rel="stylesheet" href="../../css/highlight.css">
  <link href="../../extra.css" rel="stylesheet">

  
  <script>
    // Current page data
    var mkdocs_page_name = "Adding a New Agent";
  </script>
  
  <script src="../../js/jquery-2.1.1.min.js"></script>
  <script src="../../js/modernizr-2.8.3.min.js"></script>
  <script type="text/javascript" src="../../js/highlight.pack.js"></script>
  <script src="../../js/theme.js"></script> 
  <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
      <div class="wy-side-nav-search">
        <a href="../.." class="icon icon-home"> Reinforcement Learning Coach Documentation</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        <ul class="current">
          
            <li>
    <li class="toctree-l1 ">
        <a class="" href="../..">Home</a>
        
    </li>
<li>
          
            <li>
    <li class="toctree-l1 ">
        <a class="" href="../../design/index.html">Design</a>
        
    </li>
<li>
          
            <li>
    <li class="toctree-l1 ">
        <a class="" href="../../usage/index.html">Usage</a>
        
    </li>
<li>
          
            <li>
    <ul class="subnav">
    <li><span>Algorithms</span></li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/dqn/index.html">DQN</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/double_dqn/index.html">Double DQN</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/dueling_dqn/index.html">Dueling DQN</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/categorical_dqn/index.html">Categorical DQN</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/mmc/index.html">Mixed Monte Carlo</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/pal/index.html">Persistent Advantage Learning</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/nec/index.html">Neural Episodic Control</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/bs_dqn/index.html">Bootstrapped DQN</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/n_step/index.html">N-Step Q Learning</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/value_optimization/naf/index.html">Normalized Advantage Functions</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/policy_optimization/pg/index.html">Policy Gradient</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/policy_optimization/ac/index.html">Actor-Critic</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/policy_optimization/ddpg/index.html">Deep Determinstic Policy Gradients</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/policy_optimization/ppo/index.html">Proximal Policy Optimization</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/policy_optimization/cppo/index.html">Clipped Proximal Policy Optimization</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/other/dfp/index.html">Direct Future Prediction</a>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../../algorithms/imitation/bc/index.html">Behavioral Cloning</a>
        
    </li>

        
    </ul>
<li>
          
            <li>
    <li class="toctree-l1 ">
        <a class="" href="../../dashboard/index.html">Coach Dashboard</a>
        
    </li>
<li>
          
            <li>
    <ul class="subnav">
    <li><span>Contributing</span></li>

        
            
    <li class="toctree-l1 current">
        <a class="current" href="./index.html">Adding a New Agent</a>
        
            <ul>
            
            </ul>
        
    </li>

        
            
    <li class="toctree-l1 ">
        <a class="" href="../add_env/index.html">Adding a New Environment</a>
        
    </li>

        
    </ul>
<li>
          
        </ul>
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../..">Reinforcement Learning Coach Documentation</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../..">Docs</a> &raquo;</li>
    
      
        
          <li>Contributing &raquo;</li>
        
      
    
    <li>Adding a New Agent</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <!-- language-all: python -->

<p>Coach's modularity makes adding an agent a simple and clean task, that involves the following steps:</p>
<ol>
<li>
<p>Implement your algorithm in a new file under the agents directory. The agent can inherit base classes such as <strong>ValueOptimizationAgent</strong> or <strong>ActorCriticAgent</strong>, or the more generic <strong>Agent</strong> base class.</p>
<ul>
<li>
<p><strong>ValueOptimizationAgent</strong>, <strong>PolicyOptimizationAgent</strong> and <strong>Agent</strong> are abstract classes. 
learn_from_batch() should be overriden with the desired behavior for the algorithm being implemented. If deciding to inherit from <strong>Agent</strong>, also choose_action() should be overriden.       </p>
<pre><code>def learn_from_batch(self, batch):
    """
    Given a batch of transitions, calculates their target values and updates the network.
    :param batch: A list of transitions
    :return: The loss of the training
    """
    pass

def choose_action(self, curr_state, phase=RunPhase.TRAIN):
    """
    choose an action to act with in the current episode being played. Different behavior might be exhibited when training
     or testing.

    :param curr_state: the current state to act upon.  
    :param phase: the current phase: training or testing.
    :return: chosen action, some action value describing the action (q-value, probability, etc)
    """
    pass
</code></pre>
</li>
<li>
<p>Make sure to add your new agent to <strong>agents/__init__.py</strong></p>
</li>
</ul>
</li>
<li>
<p>Implement your agent's specific network head, if needed, at the implementation for the framework of your choice. For example <strong>architectures/neon_components/heads.py</strong>. The head will inherit the generic base class Head.
    A new output type should be added to configurations.py, and a mapping between the new head and output type should be defined in the get_output_head() function at <strong>architectures/neon_components/general_network.py</strong></p>
</li>
<li>Define a new configuration class at configurations.py, which includes the new agent name in the <strong>type</strong> field, the new output type in the <strong>output_types</strong> field, and assigning default values to hyperparameters.</li>
<li>(Optional) Define a preset using the new agent type with a given environment, and the hyperparameters that should be used for training on that environment.</li>
</ol>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../add_env/index.html" class="btn btn-neutral float-right" title="Adding a New Environment"/>Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../../dashboard/index.html" class="btn btn-neutral" title="Coach Dashboard"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
	  
        </div>
      </div>

    </section>

  </div>

<div class="rst-versions" role="note" style="cursor: pointer">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
      
        <span><a href="../../dashboard/index.html" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../add_env/index.html" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>

</body>
</html>
